package com.flyme.module.base.provider.controller;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.flyme.common.core.model.ResultBody;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.model.query.PqGrid;
import com.flyme.core.base.supper.controller.BaseController;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.module.base.client.api.SysExatimeRemoteService;
import com.flyme.module.base.client.entity.SysExamseason;
import com.flyme.module.base.client.entity.SysExatime;
import com.flyme.module.base.provider.service.SysExatimeService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * 考试场次时间管理
 * @author zyh
 * @date 2020-7-28
 */
@Api(tags = "考试场次时间")
@RestController
public class SysExatimeController extends BaseController<SysExatimeService, SysExatime> implements SysExatimeRemoteService {

    /**
     * 考试安排列表
     */
    @Override
    public ResultBody list(PagerInfo pagerInfo, SysExatime exatime) {
        CriteriaQuery cq = new CriteriaQuery<EntityMap>(pagerInfo);
        cq.select("*");
        cq.eq("status", 1);
        cq.eq("examseasonId", exatime.getExamseasonId());
        PqGrid pqGrid = bizService.pageList(cq);
        return ResultBody.success(pqGrid);
    }

    /**
     * 添加/修改
     */
    @Override
    public ResultBody timeEdit(SysExatime exatime) {
        Boolean tag = bizService.saveOrUpdate(exatime);
        return ResultBody.success("操作成功").setData(tag);
    }

    /**
     * 删除场次考试时间
     */
    @Override
    public ResultBody delByTagId(@PathVariable Long id) {
        boolean tag = bizService.update(new UpdateWrapper<SysExatime>().set("status",0).eq("id",id));
        if(tag){
            return ResultBody.success("操作成功");
        }else{
            return ResultBody.failed("操作失败");
        }
    }
}
